//
//  Reachability+XHNNetState.m
//  PockPower
//
//  Created by 邢行 on 2017/7/3.
//  Copyright © 2017年 XingHang. All rights reserved.
//

#import "Reachability+XHNNetState.h"
#import "XHNHudManager.h"

@interface Reachability ()
/** 完成点击*/
@property (nonatomic,copy) void (^doneBlock)(id sender);

@end

@implementation Reachability (XHNNetState)

+(void)netWorkChanged{

    [self netWorkChanged:^(NetworkStatus res) {
        if (res == NotReachable) {
            
            NSLog(@"没网啦啦啦 %ld", res);
            [XHNHudManager showWithText:@"没网啦啦啦"];
        }
        
    }];
}

+(void)netWorkChanged:(void (^)(NetworkStatus))resBlock{

    
    // Allocate a reachability object
    Reachability* reach = [Reachability reachabilityWithHostname:@"www.baidu.com"];
    
    // Set the blocks
    reach.reachableBlock = ^(Reachability*reach)
    {
        // keep in mind this is called on a background thread
        // and if you are updating the UI it needs to happen
        // on the main thread, like this:
        dispatch_async(dispatch_get_main_queue(), ^{
            
            resBlock([reach currentReachabilityStatus]);

            NSLog(@"REACHABLE!");
            
            
        });
        
        switch ([reach currentReachabilityStatus]) {
                
            case ReachableViaWWAN:
            {
                NSLog(@"\n\n网络状态变化,不是 wifi");
                
            }
                break;
            case ReachableViaWiFi:
            {
                NSLog(@"\n\n网络状态变化,WiFi");
                
            }
                break;
            case kRaeachableVia4G:
            {
                NSLog(@"\n\n网络状态变化,4G");
                
            }
                break;
            case kReachableVia2G:
            {
                NSLog(@"\n\n网络状态变化,2G");
                
            }
                break;
                
            case kReachableVia3G:
            {
                NSLog(@"\n\n网络状态变化,3G");
                
            }
                break;
                
            default:
                break;
        }

    };
    
    reach.unreachableBlock = ^(Reachability*reach)
    {        
        dispatch_async(dispatch_get_main_queue(), ^{
            resBlock([reach currentReachabilityStatus]);
            NSLog(@"没有网络喽  不好玩 !");
        });

        NSLog(@"\n\n网络状态变化_%ld",(long)[reach currentReachabilityStatus]);

    };
    
    // Start the notifier, which will cause the reachability object to retain itself!
    [reach startNotifier];
    
    
}

@end
